package code

import (
	"fmt"
)

func ProcessSwitch1() {
	var grade string = "B"
	var score int = 90

	switch score {
	case 90:
		grade = "A"
	case 80:
		grade = "B"
	case 50, 60, 70:
		grade = "C"
	default:
		grade = "D"
	}

	//switch后面如果没有条件表达式,则会对true进行匹配
	switch {
	case grade == "A":
		fmt.Println("优秀")
	case grade == "B", grade == "C":
		fmt.Println("良好")
	case grade == "D":
		fmt.Println("及格")
	case grade == "F":
		fmt.Println("不及格")
	default:
		fmt.Println("差")
	}
	fmt.Printf("你的等级 %s \n", grade)
}

func ProcessSwitch2() {
	var s = "hello"
	switch {
	case s == "hello":
		fmt.Println("hello")
		// fallthrough会直接执行后一个case或default, 不会判断条件是否满足
		fallthrough
	case s == "world":
		fmt.Println("world2")
	case s != "world":
		fmt.Println("world1")
	}
}
